home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * Copyright (C) 1994, Silicon Graphics, Inc. * All Rights Reserved. * * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; * the contents of this file may not be disclosed to third parties, copied or * duplicated in any form, in whole or in part, without the prior written * permission of Silicon Graphics, Inc. * * RESTRICTED RIGHTS LEGEND: * Use, duplication or disclosure by the Government is subject to restrictions * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data * and Computer Software clause at DFARS 252.227-7013, and/or in similar or * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - * rights reserved under the Copyright Laws of the United States. */ #include <stdio.h> #include <string.h> #include <malloc.h> #include "Preferences.h" #include "VCal.h" #include "Utils.h" #include "path.h" #include <Vk/VkResource.h> #include <Vk/VkWarningDialog.h> Preferences *thePreferences = NULL; Preferences::Preferences(Widget w) { char *name, *adv, *cmd; if (name = VkGetResource(w, "defaultFilename", "DefaultFilename")) { _filename = pathexpandtilde(name); } else { _filename = pathexpandtilde(DEFAULT_FILENAME); } _filename0 = strdup(_filename); if (adv = VkGetResource(w, "advanceWarning", "AdvanceWarning")) { _advanceWarning = strdup(adv); } else { _advanceWarning = strdup("5 min"); } _advanceWarning0 = strdup(_advanceWarning); _updateInterval = (int) VkGetResource(w, "updateIntervalInSeconds", "UpdateIntervalInSeconds", XmRInt, "60"); _updateInterval0 = _updateInterval; _showLates = (Boolean) (int) VkGetResource(w, "showLates", "ShowLates", XmRBoolean, "False"); _showLates0 = _showLates; _saveChangesAutomatically = (Boolean) (int) VkGetResource(w, "saveChangesAutomatically", "SaveChangesAutomatically", XmRBoolean, "True"); _saveChangesAutomatically0 = _saveChangesAutomatically; _annotateFile = (Boolean) (int) VkGetResource(w, "annotateFile", "AnnotateFile", XmRBoolean, "False"); _annotateFile0 = _annotateFile; _updateIconName = (Boolean) (int) VkGetResource(w, "updateIconName", "UpdateIconName", XmRBoolean, "False"); _updateIconName0 = _updateIconName; _updateIconDate = (Boolean) (int) VkGetResource(w, "updateIconDate", "UpdateIconDate", XmRBoolean, "False"); _updateIconDate0 = _updateIconDate; _clock24 = (Boolean) (int) VkGetResource(w, "clock24", "Clock24", XmRBoolean, "False"); _clock240 = _clock24; _alarms = (Boolean) (int) VkGetResource(w, "displayAlarms", "DisplayAlarms", XmRBoolean, "True"); _alarms0 = _alarms; _notifyPopup = (Boolean) (int) VkGetResource(w, "notifyPopup", "NotifyPopup", XmRBoolean, "True"); _notifyPopup0 = _notifyPopup; _notifyBell = (Boolean) (int) VkGetResource(w, "notifyBell", "NotifyBell", XmRBoolean, "True"); _notifyBell0 = _notifyBell; _notifyMail = (Boolean) (int) VkGetResource(w, "notifyMail", "NotifyMail", XmRBoolean, "False"); _notifyMail0 = _notifyMail; _notifyConfirmDelete = (Boolean) (int) VkGetResource(w, "notifyConfirmDelete", "NotifyConfirmDelete", XmRBoolean, "True"); _notifyConfirmDelete0 = _notifyConfirmDelete; if (cmd = VkGetResource(w, "notifyCommand", "NotifyCommand")) { _notifyCommand = strdup(cmd); } else { _notifyCommand = strdup(""); } _notifyCommand0 = strdup(_notifyCommand); _annotateDay = (Boolean) (int) VkGetResource(w, "annotateDay", "AnnotateDay", XmRBoolean, "True"); _annotateDay0 = _annotateDay; _snoozeMinutes = (int) VkGetResource(w, "snoozeMinutes", "SnoozeMinutes", XmRInt, "2"); _snoozeMinutes0 = _snoozeMinutes; _hideMenuBar = (Boolean) (int) VkGetResource(w, "hideMenuBar", "HideMenuBar", XmRBoolean, "True"); _hideMenuBar0 = _hideMenuBar; _apptLength = (int) VkGetResource(w, "apptLength", "ApptLength", XmRInt, "60"); _apptLength0 = _apptLength; _gridLength = (int) VkGetResource(w, "gridLength", "GridLength", XmRInt, "60"); _gridLength0 = _gridLength; _apptSubdiv = (int) VkGetResource(w, "apptSubdiv", "ApptSubdiv", XmRInt, "4"); _apptSubdiv0 = _apptSubdiv; _snapInterval = (int) VkGetResource(w, "snapInterval", "SnapInterval", XmRInt, "30"); _snapInterval0 = _snapInterval; _annotateMonth = (Boolean) (int) VkGetResource(w, "annotateMonth", "AnnotateMonth", XmRBoolean, "True"); _annotateMonth0 = _annotateMonth; _restricted = (Boolean) (int) VkGetResource(w, "restricted", "Restricted", XmRBoolean, "True"); _restricted0 = _restricted; _restrictStart = (int) VkGetResource(w, "restrictStart", "RestrictStart", XmRInt, "8"); _restrictStart0 = _restrictStart; _restrictStop = (int) VkGetResource(w, "restrictStop", "RestrictStop", XmRInt, "19"); _restrictStop0 = _restrictStop; loadPreferences(); thePreferences = this; } Preferences::~Preferences() { free(_filename); free(_filename0); free(_notifyCommand); free(_notifyCommand0); free(_advanceWarning); free(_advanceWarning0); } /**********************************************************************/ void Preferences::setFilename(const char *v) { free(_filename); _filename = pathexpandtilde(v); } void Preferences::setAdvanceWarning(const char *v) { char str[MAXSTR]; free(_advanceWarning); if (!strchr(v, ' ')) { strcpy(str, v); strcat(str, " min"); _advanceWarning = strdup(str); } else { _advanceWarning = strdup(v); } } void Preferences::setNotifyCommand(const char *v) { free(_notifyCommand); _notifyCommand = strdup(v); } void Preferences::loadPreferences() { char path[1024], str[1024]; FILE *fd; int num; Boolean resave; resave = False; sprintf(path, "%sPref", _filename); if (fd = fopen(path, "r")) { while (fgets(str, sizeof(str), fd)) { if (!strcmp(str, "filename\n")) { if (readStr(fd, str)) { setFilename(str); } else { fprintf(stderr, "VCal: garbled 'filename' preference\n"); } } else if (!strcmp(str, "advanceWarning\n")) { if (readStr(fd, str)) { setAdvanceWarning(str); } else { fprintf(stderr, "VCal: garbled 'advanceWarning' preference\n"); } } else if (!strcmp(str, "updateInterval\n")) { if (readInt(fd, &num)) { _updateInterval = num; } else { fprintf(stderr, "VCal: garbled 'updateInterval' preference\n"); } } else if (!strcmp(str, "showLates\n")) { if (readInt(fd, &num)) { _showLates = num; } else { fprintf(stderr, "VCal: garbled 'showLates' preference\n"); } } else if (!strcmp(str, "saveChangesAutomatically\n")) { if (readInt(fd, &num)) { _saveChangesAutomatically = num; } else { fprintf(stderr, "VCal: garbled 'saveChangesAutomatically' preference\n"); } } else if (!strcmp(str, "annotateFile\n")) { if (readInt(fd, &num)) { _annotateFile = num; } else { fprintf(stderr, "VCal: garbled 'annotateFile' preference\n"); } } else if (!strcmp(str, "updateIconName\n")) { if (readInt(fd, &num)) { _updateIconName = num; } else { fprintf(stderr, "VCal: garbled 'updateIconName' preference\n"); } } else if (!strcmp(str, "updateIconDate\n")) { if (readInt(fd, &num)) { _updateIconDate = num; } else { fprintf(stderr, "VCal: garbled 'updateIconDate' preference\n"); } } else if (!strcmp(str, "clock24\n")) { if (readInt(fd, &num)) { _clock24 = num; } else { fprintf(stderr, "VCal: garbled 'clock24' preference\n"); } } else if (!strcmp(str, "displayAlarms\n")) { if (readInt(fd, &num)) { _alarms = num; } else { fprintf(stderr, "VCal: garbled 'displayAlarms' preference\n"); } } else if (!strcmp(str, "notifyPopup\n")) { if (readInt(fd, &num)) { _notifyPopup = num; } else { fprintf(stderr, "VCal: garbled 'notifyPopup' preference\n"); } } else if (!strcmp(str, "notifyBell\n")) { if (readInt(fd, &num)) { _notifyBell = num; } else { fprintf(stderr, "VCal: garbled 'notifyBell' preference\n"); } } else if (!strcmp(str, "notifyMail\n")) { if (readInt(fd, &num)) { _notifyMail = num; } else { fprintf(stderr, "VCal: garbled 'notifyMail' preference\n"); } } else if (!strcmp(str, "notifyConfirmDelete\n")) { if (readInt(fd, &num)) { _notifyConfirmDelete = num; } else { fprintf(stderr, "VCal: garbled 'notifyConfirmDelete' preference\n"); } } else if (!strcmp(str, "notifyCommand\n")) { if (readStr(fd, str)) { setNotifyCommand(str); } else { fprintf(stderr, "VCal: garbled 'notifyCommand' preference\n"); } } else if (!strcmp(str, "annotateDay\n")) { if (readInt(fd, &num)) { _annotateDay = num; } else { fprintf(stderr, "VCal: garbled 'annotateDay' preference\n"); } } else if (!strcmp(str, "snoozeMinutes\n")) { if (readInt(fd, &num)) { _snoozeMinutes = num; } else { fprintf(stderr, "VCal: garbled 'snoozeMinutes' preference\n"); } } else if (!strcmp(str, "hideMenuBar\n")) { if (readInt(fd, &num)) { _hideMenuBar = num; } else { fprintf(stderr, "VCal: garbled 'hideMenuBar' preference\n"); } } else if (!strcmp(str, "apptLength\n")) { if (readInt(fd, &num)) { _apptLength = num; } else { fprintf(stderr, "VCal: garbled 'apptLength' preference\n"); } } else if (!strcmp(str, "gridLength\n")) { if (readInt(fd, &num)) { _gridLength = num; } else { fprintf(stderr, "VCal: garbled 'gridLength' preference\n"); } } else if (!strcmp(str, "apptSubdiv\n")) { if (readInt(fd, &num)) { _apptSubdiv = num; } else { fprintf(stderr, "VCal: garbled 'apptSubdiv' preference\n"); } } else if (!strcmp(str, "snapInterval\n")) { if (readInt(fd, &num)) { _snapInterval = num; } else { fprintf(stderr, "VCal: garbled 'snapInterval' preference\n"); } } else if (!strcmp(str, "annotateMonth\n")) { if (readInt(fd, &num)) { _annotateMonth = num; } else { fprintf(stderr, "VCal: garbled 'annotateMonth' preference\n"); } } else if (!strcmp(str, "restricted\n")) { if (readInt(fd, &num)) { _restricted = num; } else { fprintf(stderr, "VCal: garbled 'restricted' preference\n"); } } else if (!strcmp(str, "restrictStart\n")) { if (readInt(fd, &num)) { _restrictStart = num; } else { fprintf(stderr, "VCal: garbled 'restrictStart' preference\n"); } } else if (!strcmp(str, "restrictStop\n")) { if (readInt(fd, &num)) { _restrictStop = num; } else { fprintf(stderr, "VCal: garbled 'restrictStop' preference\n"); } } else { if (!strcasecmp(str, "displayExactAlarms\n")) { resave = True; theWarningDialog->post("The Also Post Exact Alarm preference is obsolete.\nIf you want to display exact alarms, add ', 0 min' to Alarm Advance Notice(s)."); } else { fprintf(stderr, "VCal: unknown preference: %s", str); } readStr(fd, str); } } fclose(fd); } if (resave) { savePreferences(); } } void Preferences::savePreferences() { char path[1024]; FILE *fd; sprintf(path, "%sPref", _filename); if (fd = fopen(path, "w")) { if (strcmp(_filename, _filename0)) { fprintf(fd, "filename\n%s\n", _filename); } if (strcmp(_advanceWarning, _advanceWarning0)) { fprintf(fd, "advanceWarning\n%s\n", _advanceWarning); } if (_updateInterval != _updateInterval0) { fprintf(fd, "updateInterval\n%d\n", _updateInterval); } if (_showLates != _showLates0) { fprintf(fd, "showLates\n%d\n", _showLates); } if (_saveChangesAutomatically != _saveChangesAutomatically0) { fprintf(fd, "saveChangesAutomatically\n%d\n", _saveChangesAutomatically); } if (_annotateFile != _annotateFile0) { fprintf(fd, "annotateFile\n%d\n", _annotateFile); } if (_updateIconName != _updateIconName0) { fprintf(fd, "updateIconName\n%d\n", _updateIconName); } if (_updateIconDate != _updateIconDate0) { fprintf(fd, "updateIconDate\n%d\n", _updateIconDate); } if (_clock24 != _clock240) { fprintf(fd, "clock24\n%d\n", _clock24); } if (_alarms != _alarms0) { fprintf(fd, "displayAlarms\n%d\n", _alarms); } if (_notifyPopup != _notifyPopup0) { fprintf(fd, "notifyPopup\n%d\n", _notifyPopup); } if (_notifyBell != _notifyBell0) { fprintf(fd, "notifyBell\n%d\n", _notifyBell); } if (_notifyMail != _notifyMail0) { fprintf(fd, "notifyMail\n%d\n", _notifyMail); } if (_notifyConfirmDelete != _notifyConfirmDelete0) { fprintf(fd, "notifyConfirmDelete\n%d\n", _notifyConfirmDelete); } if (strcmp(_notifyCommand, _notifyCommand0)) { fprintf(fd, "notifyCommand\n%s\n", _notifyCommand); } if (_annotateDay != _annotateDay0) { fprintf(fd, "annotateDay\n%d\n", _annotateDay); } if (_snoozeMinutes != _snoozeMinutes0) { fprintf(fd, "snoozeMinutes\n%d\n", _snoozeMinutes); } if (_hideMenuBar != _hideMenuBar0) { fprintf(fd, "hideMenuBar\n%d\n", _hideMenuBar); } if (_apptLength != _apptLength0) { fprintf(fd, "apptLength\n%d\n", _apptLength); } if (_gridLength != _gridLength0) { fprintf(fd, "gridLength\n%d\n", _gridLength); } if (_apptSubdiv != _apptSubdiv0) { fprintf(fd, "apptSubdiv\n%d\n", _apptSubdiv); } if (_snapInterval != _snapInterval0) { fprintf(fd, "snapInterval\n%d\n", _snapInterval); } if (_annotateMonth != _annotateMonth0) { fprintf(fd, "annotateMonth\n%d\n", _annotateMonth); } if (_restricted != _restricted0) { fprintf(fd, "restricted\n%d\n", _restricted); } if (_restrictStart != _restrictStart0) { fprintf(fd, "restrictStart\n%d\n", _restrictStart); } if (_restrictStop != _restrictStop0) { fprintf(fd, "restrictStop\n%d\n", _restrictStop); } fclose(fd); } } void Preferences::useFactory() { setFilename(_filename0); setAdvanceWarning(_advanceWarning0); _updateInterval = _updateInterval0; _showLates = _showLates0; _saveChangesAutomatically = _saveChangesAutomatically0; _annotateFile = _annotateFile0; _updateIconName = _updateIconName0; _updateIconDate = _updateIconDate0; _clock24 = _clock240; _alarms = _alarms0; _notifyPopup = _notifyPopup0; _notifyBell = _notifyBell0; _notifyMail = _notifyMail0; _notifyConfirmDelete = _notifyConfirmDelete0; setNotifyCommand(_notifyCommand0); _annotateDay = _annotateDay0; _snoozeMinutes = _snoozeMinutes0; // Don't revert menubar setting // _hideMenuBar = _hideMenuBar0; _apptLength = _apptLength0; _gridLength = _gridLength0; _apptSubdiv = _apptSubdiv0; _snapInterval = _snapInterval0; _annotateMonth = _annotateMonth0; _restricted = _restricted0; _restrictStart = _restrictStart0; _restrictStop = _restrictStop0; }